package com.ruoyi.youtian.domain;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.ruoyi.Gzmx_device.domain.Gzmx_device;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysMenu;
import com.ruoyi.gzmx_scdw.domain.Gzmx_scdw;
import com.ruoyi.gzmx_scdw.domain.Gzmx_scdwVo;
import lombok.Data;
import org.apache.poi.ss.formula.functions.T;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Treeselect树结构实体类
 *
 * @author ruoyi
 */
@Data
public class TreeSelect implements Serializable
{
    private static final long serialVersionUID = 1L;

    /** 节点ID */
    private Long id;

    /** 节点名称 */
    private String label;

    /**
     * 标题
     */
    private String title;

    /**
     * 等级
     */
    private String level;

    /**
     * 对象json信息
     */
    private String info;

    /** 二级单位ID */
    private Long ejdwId;

    /** 二级单位名称 */
    private String ejdwName;

    /** 点位三级 */
    private Long dw_3_id;

    private String dw_3_name;

    /** 点位四级 */
    private Long dw_4_id;

    private String dw_4_name;

    /** 点位五级 */
    private Long dw_5_id;

    private String dw_5_name;

    /** 子节点 */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeSelect> children;


    /** 子节点 */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeSelect> child;

    public TreeSelect()
    {

    }

    public TreeSelect(Long id, String label, String title, String level)
    {
        this.id = id;
        this.label = label;
        this.title = level;
    }

    public TreeSelect(SysDept dept)
    {
        this.id = dept.getDeptId();
        this.label = dept.getDeptName();
        this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

    public TreeSelect(SysMenu menu)
    {
        this.id = menu.getMenuId();
        this.label = menu.getMenuName();
        this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

    public TreeSelect(TWorkspaceCategory workspaceCategory)
    {
        this.id = workspaceCategory.getWorkspaceCategoryId();
        this.label = workspaceCategory.getCategoryName();
        this.level = workspaceCategory.getType();
        this.title  = workspaceCategory.getCategoryName();
        this.children = workspaceCategory.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

    public TreeSelect(Gzmx_scdwVo gzmxScdwVo)
    {
        this.id = gzmxScdwVo.getId();
        this.label = "scdw";
        this.title  = gzmxScdwVo.getDwmc();
        this.level = gzmxScdwVo.getJb().toString();
        if(gzmxScdwVo.getJb() == 5){
            this.ejdwId = gzmxScdwVo.getEjdwId();
            this.ejdwName = gzmxScdwVo.getEjdwName();
            this.dw_3_id = gzmxScdwVo.getDw_3_id();
            this.dw_3_name = gzmxScdwVo.getDw_3_name();
            this.dw_4_id = gzmxScdwVo.getDw_4_id();
            this.dw_4_name = gzmxScdwVo.getDw_4_name();
            this.dw_5_id = gzmxScdwVo.getDw_5_id();
            this.dw_5_name = gzmxScdwVo.getDw_5_name();

        }
        this.children = gzmxScdwVo.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

    public TreeSelect(Gzmx_device gzmxDevice)
    {
        this.id = gzmxDevice.getId();
        this.label = "device";
        this.level = "6";
        this.title  = gzmxDevice.getDev_name();
        this.ejdwId = gzmxDevice.getDev_azdw2_id();
        this.ejdwName = gzmxDevice.getDev_azdw2_name();
        this.dw_3_id = gzmxDevice.getDev_azdw3_id();
        this.dw_3_name = gzmxDevice.getDev_azdw3_name();
        this.dw_4_id = gzmxDevice.getDev_azdw4_id();
        this.dw_4_name = gzmxDevice.getDev_azdw4_name();
        this.dw_5_id = gzmxDevice.getDev_azdw5_id();
        this.dw_5_name = gzmxDevice.getDev_azdw5_name();
    }


    public TreeSelect(PointEquipment pointEquipment)
    {
        this.id = pointEquipment.getId(); // 传送用于设备点位关系解绑
        this.label = "tag";
        this.level = "7";
        this.title  = pointEquipment.getTagName();
    }


    public TreeSelect(Template template)
    {
        this.id = template.getTemplateId();
        this.label = "template";
        this.level = "6";
        this.title  = template.getTemplateName();
    }

    public TreeSelect(TSceneCategory sceneCategory){
        this.id = sceneCategory.getSceneId();
        this.label = "scene";
        this.level = "6";
        this.title  = sceneCategory.getSceneName();
    }

    public TreeSelect(TSceneCategoryTreeSelect sceneCategoryTreeSelect){
        this.id = sceneCategoryTreeSelect.getId();
        this.label = "scene";
        this.level = sceneCategoryTreeSelect.getLevel();
        this.title = sceneCategoryTreeSelect.getTitle();
        this.children = sceneCategoryTreeSelect.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }
}
